package com.ibangnuo.manage.service.customs;

import com.ibangnuo.framework.domain.Customs;
import com.ibangnuo.framework.domain.User;
import com.ibangnuo.framework.domain.request.customs.CustomsRequest;
import com.ibangnuo.framework.model.response.QueryResponseResult;
import com.ibangnuo.manage.dao.customs.CustomsRepository;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;

/**
 * @Author: wwy
 * @Date: 2020-03-09 15:53
 * 报单管理
 */
@Service
public class CustomsService {
    @Autowired
    private CustomsRepository customsRepository;
    /**
     * 分页条件查询
     * @param customsRequest
     * @return
     */
    public QueryResponseResult findList(CustomsRequest customsRequest,int page,int size){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        if(customsRequest == null){
            customsRequest = new CustomsRequest();
        }

        String id = user.getId();
        Customs customs = new Customs();
        ExampleMatcher exampleMatcher = ExampleMatcher.matching();
        Example<? extends Customs> example = Example.of(customs,exampleMatcher);
        if(page <= 0){
            page = 1;
        }
        page = page - 1;
        if(size <=0){
            size = 10;
        }
        Sort sort = new Sort(Sort.Direction.DESC,"createTime");
        Pageable pageable = PageRequest.of(page,size,sort);

        customsRepository.findAll(example,pageable);
        return null;
    }
}
